package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.annotation.RequireLogin;
import cn.wolfcode.luowowo.annotation.UserParam;
import cn.wolfcode.luowowo.domain.Banner;
import cn.wolfcode.luowowo.domain.User;
import cn.wolfcode.luowowo.domain.UserInfo;
import cn.wolfcode.luowowo.service.IBannerService;
import cn.wolfcode.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IBannerService bannerService;

    @GetMapping("/banners/travel")
    public Object travel(){
        List<Banner> list=bannerService.queryTop5();
        return JsonResult.success(list);
    }


    @GetMapping("/banners/strategy")
    public Object strategy(){
        List<Banner> list=bannerService.queryTop1();
        return JsonResult.success(list.get(0));
    }


    @RequireLogin
    @GetMapping("/travel")
    public Object travel(String ownerId,HttpServletRequest request){
        Map<String, Object> map = new HashMap<>();
        User user= bannerService.getViewNum(ownerId,request);
        int todatView=bannerService.increaseTodayview(ownerId,request);
        map.put("totalView",user.getTotalView());
        map.put("todayView",todatView);
        return JsonResult.success(map);
    }
    @RequireLogin
    @GetMapping("/queryTop8")
    public Object queryTop8(String ownerId){
        Map<String, Object> map = new HashMap<>();
        List<UserInfo> users= bannerService.queryTop8ById(ownerId);
        return JsonResult.success(users);
    }

    @RequireLogin
    @GetMapping("/show")
    public Object show(String ownerId){
        List<UserInfo> users= bannerService.show(ownerId);
        return JsonResult.success(users);
    }



}
